<template>
  <el-dialog
    :title="NoRulesTitle"
    :visible.sync="NoRulesDialogVisible"
    width="30%"
    :close-on-click-modal="false"
    :before-close="NoRulesDialogClose"
    @close="closeDialog"
  >
    <div>
      <el-form ref="NoRulesForm" :rules="NoRules" :model="arNoPolicy" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="规则名称" prop="policyName">
              <el-input v-model="arNoPolicy.policyName" placeholder="请输入规则名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="档号规则" prop="fileFsmt">
              <selectData
                :selectFormat="selectFormat"
                :arNoPolicy="arNoPolicy"
                pholder="请选择档号规则"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="是否启用">
              <el-radio-group v-model="arNoPolicy.isOpen">
                <el-radio label="1">是</el-radio>
                <el-radio label="0">否</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="描述">
              <el-input type="textarea" v-model="arNoPolicy.remark"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="NoRulesConfirm">确 定</el-button>
      <el-button @click="NoRulesDialogClose">取 消</el-button>
    </span>
  </el-dialog>
</template>

<script>
import selectData from '@/components/selectData'
import { addArNoPolicy, submitUpdateArNoPolicy } from '@/api/system/sort'
export default {
  name: 'NoRulesDialog',
  props:['NoRulesDialogVisible','NoRulesTitle','selectFormat','queryParams','getArNoPolicy','arNoPolicy'],
  components:{
    selectData
  },
  data() {
    return {
      NoRules:{
        policyName:[
          { required: true, message: '请输入规则名称', trigger: 'blur' }
        ],
        fileFsmt:[
          { required: true, message: '请选择档号规则', trigger: 'blur' }
        ]
      }
    };
  },
  methods:{
    closeDialog(){
      for (const key in this.arNoPolicy) {
        this.arNoPolicy[key] = ''
      }
      this.arNoPolicy.isOpen = '1'
    },
    NoRulesDialogClose(){
      this.$emit('closeNoRules')
    },
    // 档号规则弹窗确定
    async NoRulesConfirm(){
      this.$confirm('确认提交吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const params = {}
        params.sortNo = this.queryParams.sortPrantNo
        params.fileFsmt = this.arNoPolicy.fileFsmt
        params.isOpen = this.arNoPolicy.isOpen
        params.policyName = this.arNoPolicy.policyName
        params.remark = this.arNoPolicy.remark
        if(this.NoRulesTitle === '新增档号规则'){
          this.add(params)
        }else {
          this.update(params)
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消提交'
        });
      });
    },
    async add(params){
      const res = await addArNoPolicy(params)
      if(res.code === 200){
        this.$message.success(res.msg)
        this.$emit('closeNoRules')
        this.getArNoPolicy()
      }
    },
    async update(params){
      const res = await submitUpdateArNoPolicy(params)
      if(res.code === 200){
        this.$message.success(res.msg)
        this.$emit('closeNoRules')
        this.getArNoPolicy()
      }
    }
  }
}
</script>

<style scoped>

</style>


